package com.example.demonstrate.wang.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author along
 * @Date 2024/6/27 16:27
 */

@Service
@Slf4j
public class TimeCursorService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void checkAndUpdateTimeCursor(String key, String value) {
        Boolean hasKey = redisTemplate.hasKey(key);
        if (Boolean.TRUE.equals(hasKey)) {
            // 如果key不存在，则设置为startTime
            redisTemplate.opsForValue().set(key, value);
        }
    }

    public void updateTimeCursor(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
    }
}
